package com.definity.toolkit.report;

import java.io.Serializable;
import java.util.Iterator;
import java.util.List;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;

import com.definity.toolkit.domain.DynamicDomain;

public class DynamicDomainJRDataSource<T extends Serializable> implements JRDataSource {

	private final Iterator<DynamicDomain<T>> iterator;

	private DynamicDomain<?> domain;

	public DynamicDomainJRDataSource(List<DynamicDomain<T>> list) {
		iterator = list.iterator();
	}

	@Override
	public Object getFieldValue(JRField field) throws JRException {
		return domain.getProperty(field.getName());
	}

	@Override
	public boolean next() throws JRException {
		boolean hasNext = iterator.hasNext();
		if (hasNext)
			domain = iterator.next();
		return hasNext;
	}

}
